<template>
	<view class="nav-content" :style="`height:${navBarHeight + 44}px;`">
		<view class="nav-bar" :style="`height:${navBarHeight + 44}px;`">
			<!-- #ifdef MP-WEIXIN -->
			<view :style="`height:${menuHeight*2}rpx; padding-top:${menuTop}px;
			left: ${menuRight}px;right:${menuRight}px;`" class="nav-bar-cont">
			<!-- #endif -->

				<!-- #ifdef APP-PLUS -->
				<view :style="`height:${navBarHeight*2}rpx;`"></view>
				<view :style="`height:${44*2}rpx; margin:0 auto;`" class="nav-bar-cont">
				<!-- #endif -->
				
					<view class="left_cont">
						<view class="left_back" @click="onBack">
							<!-- 背景箭头 -->
							<template v-if="bgIconFlag">
								<view class="bgArrows">
									<uni-icons v-if="arrows" color="#fff" type="back" size="20"></uni-icons>
								</view>
							</template>
							<!-- 箭头文案 -->
							<template v-else-if="arrows && !iconFlag">
								<uni-icons class="icon" v-if="arrows" color="#fff" type="back" size="24"></uni-icons>
								<text v-if="arrowsTextFlag" class="title">{{arrowsText}}</text>
							</template>
							<!-- 单图 -->
							<template v-else-if="iconFlag">
								<text class="iconfont icon-exchange-alt"></text>
								<!-- <uni-icons color="#fff" type="back" size="20"></uni-icons> -->
							</template>
						</view>
					</view>
					<view class="center_cont">
						<text class="title">{{title}}</text>
						<text @click="onMiddle" v-if="titleIcon" class="iconfont icon-exchange-alt"></text>
					</view>
					<view class="right_cont">
						<!-- #ifdef APP-PLUS -->
						<view v-if="logOut" @click="onOut" class="out">
							退出
						</view>
						<!-- #endif -->
					</view>
					
				<!-- #ifdef APP-PLUS -->
				</view>
				<!-- #endif -->
				
			<!-- #ifdef MP-WEIXIN -->
			</view>
			<!-- #endif -->
			
		</view>
	</view>
</template>

<script>
	import tools from '../../utils/tools';
	export default {
		name: "nav-app",
		props: {
			arrows: { // 箭头
				type: Boolean,
				default: true
			},
			arrowsText: { // 箭头文案
				type: String,
				default: '返回'
			},
			arrowsTextFlag: { // 箭头文案显示
				type: Boolean,
				default: false
			},
			bgIconFlag: { // 带背景的箭头
				type: Boolean,
				default: false,
			},
			iconFlag: { // 背景图
				type: Boolean,
				default: false,
			},
			title: {
				type: String,
				// default: '我主页'
			},
			titleIcon: {
				type: Boolean,
				default: false,
			},
			bgColor: {
				type: String,
				default: '#0076f6'
			},
			logOut: {
				type: Boolean,
				default: false,
			}
		},
		data() {
			return {
				navBarHeight: 0,
				menuRight: 0,
				menuTop: 0,
				menuHeight: 0,
				data: 0, // 返回的页面
			};
		},
		mounted() {
			// 获取系统信息
			const systemInfo = uni.getSystemInfoSync();
			// console.log('systemInfo', systemInfo);
			// 导航栏高度 = 状态栏高度 + 44
			this.navBarHeight = systemInfo.statusBarHeight || 0;

			// #ifdef MP-WEIXIN
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect(); // 胶囊按钮位置信息
			this.menuRight = systemInfo.screenWidth - menuButtonInfo.right;

			// 电脑端小程序 || 安卓手机端小程序与开发者工具
			if (systemInfo.platform == "windows") this.menuTop = 0;
			else if (systemInfo.platform == "android" || systemInfo.platform == "devtools") {
				this.menuTop = menuButtonInfo.top
			}
			this.menuHeight = menuButtonInfo.height;
			//#endif
		},
		methods: {
			onBack() {
				if (this.arrows || this.bgIconFlag) {
					var pages = getCurrentPages() // 获取栈实例
					let currentRoute = pages[pages.length - 1]?.route;
					// console.log('Back', pages);
					uni.navigateBack();
				} else if (this.iconFlag) {
					uni.navigateBack();
				}
			},
			// 点击中间
			onMiddle(){},
			// 退出登入(已弃用)
			onOut() {
				uni.clearStorageSync();
			}
		}
	}
</script>

<style lang="scss">
	.nav-content {
		// overflow: hidden;
	}

	.nav-bar {
		// border:1px solid red;
		position: fixed;
		left: 0;
		right: 0;
		z-index: 999;
		background-color: v-bind(bgColor);
	}

	.nav-bar-cont {
		// border:1px solid black;
		position: absolute;
		/* #ifdef APP-PLUS */
		left: 2%;
		right: 2%;
		/* #endif */

		display: flex;
		justify-content: space-between;
		align-items: center;
		color: white;

		.left_cont {
			box-sizing: border-box;
			width: 230rpx;
			display: flex;
			justify-content: flex-start;

			.left_back {
				display: flex;
				align-items: center;

				.icon {
					// border: 1px solid black;
					/* #ifdef MP-WEIXIN */
					padding-top: 10rpx;
					/* #endif */
				}

				.title {
					// border: 1px solid red;
					font-size: 40rpx;
					/* #ifdef APP-PLUS */
					padding-top: 6rpx;
					/* #endif */
				}

				.bgArrows {
					width: 45rpx;
					height: 45rpx;
					border: 5rpx solid white;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				.iconfont {
					font-size: 48rpx;
				}

				.left_img {
					height: 38rpx;
					width: 38rpx;
				}
			}
		}

		.center_cont {
			// border:1px solid red;
			// width: 210rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.title {
				font-size: 40rpx;
				padding-right: 10rpx;
			}

			.icon-exchange-alt {
				font-size: 40rpx !important;
			}
		}

		.right_cont {
			width: 230rpx;
			display: flex;
			justify-content: flex-end;

			// border:1px solid red;
			.out {
				font-size: 36rpx;
				// border:1px solid red;
			}
		}
	}

	.img {
		width: 35rpx;
		height: 35rpx;
	}

	.po {
		box-sizing: border-box;
		background-color: pink;
		height: 40px;
		// border:1px solid red;
	}
</style>